/// 标签栏数据模型
class TabModel {
  String name = "Writing";
  List<QuestionModel> questions = [];

  TabModel({required this.name, required this.questions});

  // 从json中加载数据
  TabModel.fromJson(Map<String, dynamic> json) {
    name = json['name'] ?? '';
    questions = (json['questions'] ?? [])
        .map<QuestionModel>((e) => QuestionModel.fromJson(e))
        .toList();
  }

  Map<String, dynamic> toJson() => {
        'name': name,
        'questions': questions.map((e) => e.toJson()).toList(),
      };
}

/// 问题数据模型
class QuestionModel {
  late bool must;
  String? question, answer, placeholder;

  QuestionModel({
    required this.must,
    this.question = "Writing Topic",
    this.answer = "",
    this.placeholder = "The writing topic has not been filled in",
  });

  // 从json中加载数据
  QuestionModel.fromJson(Map<String, dynamic> json) {
    must = json['must'] ?? true;
    question = json['question'];
    answer = json['answer'];
    placeholder = json['placeholder'];
  }

  // 转为json
  Map<String, dynamic> toJson() => {
        'must': must,
        'question': question,
        'answer': answer,
        'placeholder': placeholder,
      };
}
